from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def test_order_search():
    driver = webdriver.Chrome()
    driver.get("https://admin.example.com")
    
    # 登录后台
    driver.find_element(By.ID, "username").send_keys("admin")
    driver.find_element(By.ID, "password").send_keys("Admin@123")
    driver.find_element(By.XPATH, "//button[contains(text(),'登录')]").click()
    
    # 进入订单管理页
    WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.LINK_TEXT, "订单管理"))
    ).click()
    
    # 输入订单号搜索
    order_id = "ORD202311011234"
    search_input = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "#search-input"))
    )
    search_input.send_keys(order_id)
    driver.find_element(By.XPATH, "//button[@id='search-btn']").click()
    
    # 验证搜索结果
    result = WebDriverWait(driver, 5).until(
        EC.visibility_of_element_located((By.XPATH, f"//td[text()='{order_id}']"))
    )
    assert result.is_displayed(), "订单搜索失败"
    driver.quit()